//
//  TextFieldViewController.m
//  CoreUser
//
//  Created by Demi on 20/04/2017.
//  Copyright © 2017 Azazie. All rights reserved.
//

#import "TextFieldViewController.h"
#import "CoreUserTextFieldComponent.h"
#import <Masonry/Masonry.h>
#import <ReactiveObjC/ReactiveObjC.h>

@interface TextFieldViewController ()

@property (nonatomic, weak) CoreUserTextFieldComponent *emailTextFieldComponent;

@end

@implementation TextFieldViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:nil action:nil];
    @weakify(self);
    self.navigationItem.rightBarButtonItem.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        @strongify(self);
        self.emailTextFieldComponent.errorLabel.text = @"Invalid";
        self.emailTextFieldComponent.invalid = YES;
        return RACSignal.empty;
    }];
    
    CoreUserTextFieldComponent *emailTextFieldComponent = [[CoreUserTextFieldComponent alloc] init];
    _emailTextFieldComponent = emailTextFieldComponent;
    [self.view addSubview:emailTextFieldComponent];
    [emailTextFieldComponent mas_makeConstraints:^(MASConstraintMaker *maker){
        maker.left.and.right.equalTo(self.view);
        maker.centerY.equalTo(self.view);
        maker.height.mas_equalTo(CoreUserTextFieldComponentExpectedHeight);
    }];
    
    emailTextFieldComponent.placeholderLabel.text = @"Email";
}

@end
